import { exec } from 'child_process';
import { promisify } from 'util';

/**
 * 异步执行命令的工具函数
 */
export const execAsync = promisify(exec);

/**
 * 执行命令并返回结果
 */
export async function executeCommand(command: string, cwd?: string): Promise<{
  stdout: string;
  stderr: string;
}> {
  try {
    const result = await execAsync(command, { cwd });
    return {
      stdout: result.stdout,
      stderr: result.stderr
    };
  } catch (error: any) {
    throw new Error(`命令执行失败: ${error.message}`);
  }
}